﻿using DalatCooking.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DalatCooking.Core.Helper;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Page.Title = Settings.Setting("site.sitename");      
        string menu = Server.HtmlEncode(Request.QueryString["page"]);
        switch (menu)
        {
            default:
                // PlaceHolder1.Controls.Add(LoadControl(GetFileUserControl("Home.ascx")));
                LoadUserControl("Home");
                break;
            case "home":
                LoadUserControl("Home");
                break;
            case "account":
                Person p = Session.GetPersonLogged();
                LoadUserControl((p != null) ? "UserAccount" : "Login");
                break;
            case "myaccount":
                LoadUserControl("UserAccount");
                break;
            case "register":
                LoadUserControl("Register");
                break;
            case "about":
                LoadUserControl("Page");
                break;
            case "contact":
             
                LoadUserControl("Contact");
                break;
            case "category":
                LoadUserControl("Category");
                break;
            case "allcategory":
                LoadUserControl("CategoryAll");
                break;
            case "courseall":
                LoadUserControl("courseall");
                break;
            case "coursedetail":
                LoadUserControl("CourseDetail");
                break;
            case "product":
                LoadUserControl("ProductDetail");
                break;
            case "page": LoadUserControl("Page");
                break;

            case "cart": LoadUserControl("Cart");
                break;
            case "viewcart": LoadUserControl("Cart");
                break;
            case "complete":
                LoadUserControl("CheckoutComplete");
                break;

            case "video":
                LoadUserControl("Videos");
                break;
            case "videodetail":
                LoadUserControl("VideoDetail");
                break;
            case "blog":
                LoadUserControl("Blog");
                break;
            case "post":
                LoadUserControl("BlogDetail");
                break;
            case "search":
                LoadUserControl("Search");
                break;

            case "docdetail":
                LoadUserControl("DocumentDetail");
                break;
            case "document":
                LoadUserControl("DocumentCourse");
                break;
          
        }
    }
    private void LoadUserControl(string controlName)
    {
        string controlUrl = @"/UserControls/" + controlName + ".ascx";
        PlaceHolder1.Controls.Add(LoadControl(controlUrl));
    }
    protected override void OnPreLoad(EventArgs e)
    {
        string appKey = AppConfig.Instance.String("ApplicationKey");
        if (!IsPostBack)
        {
            if (AppConfig.Instance.Int("Install") == 1)
                Response.Redirect("/install");
        }
        
        if (!appKey.Equals(MyEncode.Encrypt("LeThanhTuan").ToUpper()))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert",
          "alert('Cảnh báo: Website chưa có bản quyền. Vui lòng liên hệ (A. Tuấn) Số điện thoại [097 6060 432 ] để mua bản quyền cho website của bạn.!');", true);
        }
       
        base.OnPreLoad(e);
    }
}